
package com.epfresh.supplier.adapter;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.OrderDetailAgent;

import multitype.ItemViewBinder;

public class OrderStateViewBinder
    extends ItemViewBinder<OrderDetailAgent.ContentBean.StageStatusListBean, OrderStateViewBinder.ViewHolder>{
    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_order_state, parent, false);
        return new ViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull OrderDetailAgent.ContentBean.StageStatusListBean post) {
        if(getPosition(holder)==0){
            holder.v_item_order_line_1.setVisibility(View.INVISIBLE);
        }else{
            holder.v_item_order_line_1.setVisibility(View.VISIBLE);
        }
        if(getPosition(holder)==getAdapter().getItemCount()-1){
            holder.v_item_order_line_2.setVisibility(View.INVISIBLE);
        }else {
            holder.v_item_order_line_2.setVisibility(View.VISIBLE);
        }
        if(post.getCode()==null){
            holder.iv_item_order_state.setImageResource(R.mipmap.order_state_line);
            holder.v_item_order_line_1.setBackgroundColor(Color.RED);
            holder.v_item_order_line_2.setBackgroundColor(Color.RED);
            holder.tv_item_order_state_title.setText("");
            return;
        }

        if(post.isActivity()){
            holder.iv_item_order_state.setImageResource(R.mipmap.order_state_active);
            holder.v_item_order_line_1.setBackgroundColor(Color.RED);
            holder.v_item_order_line_2.setBackgroundColor(Color.RED);
        }else {
            holder.iv_item_order_state.setImageResource(R.mipmap.order_state_grey);
            holder.v_item_order_line_1.setBackgroundColor(Color.parseColor("#e5e5e5"));
            holder.v_item_order_line_2.setBackgroundColor(Color.parseColor("#e5e5e5"));
        }

        if(post.isCurNode()&&!post.isActivity()){
            holder.v_item_order_line_1.setBackgroundColor(Color.RED);
            holder.v_item_order_line_2.setBackgroundColor(Color.parseColor("#e5e5e5"));
            holder.iv_item_order_state.setImageResource(R.mipmap.order_state_now);
        }

        holder.tv_item_order_state_title.setText(post.getTitle());
    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        private View v_item_order_line_1, v_item_order_line_2;
        private ImageView iv_item_order_state;
        private TextView tv_item_order_state_title;

        ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_item_order_state_title = itemView.findViewById(R.id.tv_item_order_state_title);
            v_item_order_line_1 = itemView.findViewById(R.id.v_item_order_line_1);
            v_item_order_line_2 = itemView.findViewById(R.id.v_item_order_line_2);
            iv_item_order_state = itemView.findViewById(R.id.iv_item_order_state);
            tv_item_order_state_title = itemView.findViewById(R.id.tv_item_order_state_title);
        }
    }
}
